package com.nercel.dsj.gksales.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.nercel.dsj.gksales.dao.mapper.BalanceRecordMapper;
import com.nercel.dsj.gksales.model.ListResult;
import com.nercel.dsj.gksales.model.QueryParams;
import com.nercel.dsj.gksales.model.dto.BalanceRecordResultDTO;
import com.nercel.dsj.gksales.model.entity.BalanceRecord;
import com.nercel.dsj.gksales.service.BalanceRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BalanceRecordServiceImpl implements BalanceRecordService {

	private final BalanceRecordMapper balanceRecordMapper;

	@Override
	public void save(BalanceRecord balanceRecord) {
		balanceRecordMapper.insertSelective(balanceRecord);
	}

	@Override
	public void update(BalanceRecord balanceRecord) {
		balanceRecordMapper.updateByPrimaryKeySelective(balanceRecord);
	}

	@Override
	public BalanceRecord findById(Integer integer) {
		return balanceRecordMapper.selectByPrimaryKey(integer);
	}

	@Override
	public List<BalanceRecord> listAll() {
		return null;
	}

	@Override
	public void delete(Integer integer) {
		balanceRecordMapper.deleteByPrimaryKey(integer);
	}

	@Override
	public ListResult<BalanceRecordResultDTO> listWithPaging(QueryParams queryParams) {
		Page<BalanceRecordResultDTO> page = PageHelper.startPage(queryParams.getPageNumber(), queryParams.getPageSize());
		balanceRecordMapper.query(queryParams);
		return new ListResult<>(page);
	}

}

